package com.madi.company.ui.main.activity;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jaydenxiao.common.base.BaseActivity;
import com.madi.company.R;
import com.madi.company.app.AppConstant;
import com.madi.company.utils.DnUtil;
import com.madi.company.widget.WordWrapView;
import com.zhy.android.percent.support.PercentRelativeLayout;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 简历详情界面
 */
public class ResumeDetailActivity extends BaseActivity {


    @Bind(R.id.news_detail_photo_iv)
    ImageView mNewsDetailPhotoIv;
    @Bind(R.id.toolbar_layout)
    CollapsingToolbarLayout mToolbarLayout;
    @Bind(R.id.app_bar)
    AppBarLayout mAppBar;
    @Bind(R.id.percent_relative)
    PercentRelativeLayout mPercentRelativeLayout;
    @Bind(R.id.text_view_job_name)
    TextView mTextViewJobName;
    @Bind(R.id.text_view_refresh_time)
    TextView mTextViewRefreshTime;
    @Bind(R.id.toolbar)
    Toolbar mToolbar;
    @Bind(R.id.view)
    View mView;
    @Bind(R.id.textView10)
    TextView mTextView10;
    @Bind(R.id.text_view_name)
    TextView mTextViewName;
    @Bind(R.id.linear_layout_name)
    LinearLayout mLinearLayoutName;
    @Bind(R.id.text_view_sex)
    TextView mTextViewSex;
    @Bind(R.id.linear_layout_sex)
    LinearLayout mLinearLayoutSex;
    @Bind(R.id.text_view_birthday)
    TextView mTextViewBirthday;
    @Bind(R.id.linear_layout_birthday)
    LinearLayout mLinearLayoutBirthday;
    @Bind(R.id.text_view_live_city)
    TextView mTextViewLiveCity;
    @Bind(R.id.linear_layout_live_city)
    LinearLayout mLinearLayoutLiveCity;
    @Bind(R.id.textView9)
    TextView mTextView9;
    @Bind(R.id.text_view_email)
    TextView mTextViewEmail;
    @Bind(R.id.linear_layout_email)
    LinearLayout mLinearLayoutEmail;
    @Bind(R.id.linear_layout_personal_information)
    LinearLayout mLinearLayoutPersonalInformation;
    @Bind(R.id.text_view_response_rate)
    TextView mTextViewResponseRate;
    @Bind(R.id.text_view_professional_rate)
    TextView mTextViewProfessionalRate;
    @Bind(R.id.text_view_about_rate)
    TextView mTextViewAboutRate;
    @Bind(R.id.text_view_appearance_rate)
    TextView mTextViewAppearanceRate;
    @Bind(R.id.textView8)
    TextView mTextView8;
    @Bind(R.id.text_view_property)
    TextView mTextViewProperty;
    @Bind(R.id.text_view_job_type)
    TextView mTextViewJobType;
    @Bind(R.id.text_view_trade_type)
    TextView mTextViewTradeType;
    @Bind(R.id.text_view_district)
    TextView mTextViewDistrict;
    @Bind(R.id.text_view_salary)
    TextView mTextViewSalary;
    @Bind(R.id.text_view_arrival_time)
    TextView mTextViewArrivalTime;
    @Bind(R.id.text_view_exceptional_case)
    TextView mTextViewExceptionalCase;
    @Bind(R.id.text_view_identity)
    TextView mTextViewIdentity;
    @Bind(R.id.word_wrap_view_self_introduction)
    WordWrapView mWordWrapViewSelfIntroduction;
    @Bind(R.id.text_view_self_introduction)
    TextView mTextViewSelfIntroduction;
    @Bind(R.id.linear_layout_work_experience)
    LinearLayout mLinearLayoutWorkExperience;
    @Bind(R.id.linear_layout_educational_background)
    LinearLayout mLinearLayoutEducationalBackground;
    @Bind(R.id.word_warp_view_proficient)
    WordWrapView mWordWarpViewProficient;
    @Bind(R.id.word_warp_view_practised)
    WordWrapView mWordWarpViewPractised;
    @Bind(R.id.word_wrap_view_commonly)
    WordWrapView mWordWrapViewCommonly;
    @Bind(R.id.text_view_report)
    TextView mTextViewReport;
    @Bind(R.id.resume_chat)
    ImageView mResumeChat;
    @Bind(R.id.resume_collection)
    ImageView mResumeCollection;
    @Bind(R.id.resume_remind)
    ImageView mResumeRemind;
    @Bind(R.id.resume_picture)
    ImageView mResumePicture;
    @Bind(R.id.inviteBtn)
    Button mInviteBtn;
    @Bind(R.id.getAllResumeBtn)
    Button mGetAllResumeBtn;
    private CollapsingToolbarLayoutState state;

    private enum CollapsingToolbarLayoutState {
        EXPANDED,
        COLLAPSED,
        INTERNEDIATE
    }

    /**
     * 入口
     *
     * @param mContext
     */
    public static void startAction(Context mContext, View view) {
        Intent intent = new Intent(mContext, ResumeDetailActivity.class);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ActivityOptions options = ActivityOptions
                    .makeSceneTransitionAnimation((Activity) mContext, view, AppConstant.TRANSITION_ANIMATION_NEWS_PHOTOS);
            mContext.startActivity(intent, options.toBundle());
        } else {
            //让新的Activity从一个小的范围扩大到全屏
            ActivityOptionsCompat options = ActivityOptionsCompat
                    .makeScaleUpAnimation(view, view.getWidth() / 2, view.getHeight() / 2, 0, 0);
            ActivityCompat.startActivity((Activity) mContext, intent, options.toBundle());
        }

    }

    @Override
    public int getLayoutId() {
        return R.layout.act_resume_detail;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        loadView();

    }

    @OnClick({R.id.resume_chat, R.id.resume_collection, R.id.resume_remind, R.id.resume_picture, R.id.inviteBtn, R.id.getAllResumeBtn})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.resume_chat:
                break;
            case R.id.resume_collection:
                break;
            case R.id.resume_remind:
                break;
            case R.id.resume_picture:
                break;
            case R.id.inviteBtn:
                break;
            case R.id.getAllResumeBtn:
                break;
        }
    }

    //toolbar 和 appbar中间变化和点击事件 另写了个方法
    private void loadView() {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    finishAfterTransition();
                } else {
                    finish();
                }
            }
        });
        mToolbar.inflateMenu(R.menu.resume_detail);
        mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_web_view:
                        break;
                    case R.id.action_browser:
                        DnUtil.showShare(ResumeDetailActivity.this);
                        break;
                }
                return true;
            }
        });
        mAppBar.addOnOffsetChangedListener
                (new AppBarLayout.OnOffsetChangedListener() {
                     /**
                      *  监听appbar的滑动状态
                      * @param appBarLayout
                      * @param verticalOffset  <0表示向上滑动
                      */
                     @Override
                     public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                         if (verticalOffset < 0) {
                             mPercentRelativeLayout.setVisibility(View.GONE);
                         } else {
                             mPercentRelativeLayout.setVisibility(View.VISIBLE);
                         }
                         if (verticalOffset == 0) {
                             // 展开的状态
                             if (state != CollapsingToolbarLayoutState.EXPANDED) {
                                 state = CollapsingToolbarLayoutState.EXPANDED;//修改状态标记为展开
                                 mToolbarLayout.setTitle("");//设置title
                             }
                         } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
                             //滑动结束之后
                             if (state != CollapsingToolbarLayoutState.COLLAPSED) {
                                 mToolbarLayout.setTitle("丁宁的简历");//设置title不显示
                                 state = CollapsingToolbarLayoutState.COLLAPSED;//修改状态标记为折叠
                             }

                         } else {
                             if (state != CollapsingToolbarLayoutState.INTERNEDIATE) {
                                 // 滑动过程中 中间的状态
                                 if (state == CollapsingToolbarLayoutState.COLLAPSED) {
                                 }
                                 mToolbarLayout.setTitle("");//设置title为INTERNEDIATE
                                 state = CollapsingToolbarLayoutState.INTERNEDIATE;//修改状态标记为中间
                             }
                         }
                     }
                 }
                );
    }

}
